package com.xq.controller;


import com.xq.apis.UmsOrganizationsApis;
import com.xq.constants.ErrorCodeConstants;
import com.xq.dto.UmsOrganizations.*;
import com.xq.service.IUmsOrganizationsService;
import com.xq.service.IUmsUserOrganizationService;
import com.xq.vo.JsonVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  组织管理控制器
 * </p>
 *
 * @author wuven
 * @since 2025-05-26
 */
@Api(tags = "组织管理")
@RestController
@RequestMapping("/ums-organizations")
public class UmsOrganizationsController implements UmsOrganizationsApis {

    @Autowired
    private IUmsOrganizationsService iUmsOrganizationsService;

    @Autowired
    private IUmsUserOrganizationService userOrganizationService;

    @ApiOperation("创建组织")
    @PostMapping("/add-organizations")
    @Override
    public JsonVO<String> addOrganizations(@RequestBody UmsOrganizationsCreatedDTO createdDTO) {
        iUmsOrganizationsService.addOrganizations(createdDTO);
        return JsonVO.success(ErrorCodeConstants.SUCCESS);
    }

    @ApiOperation("删除组织")
    @DeleteMapping("/delete-organizations")
    @Override
    public JsonVO<String> deleteOrganizations(@RequestParam String organizationId) {
        iUmsOrganizationsService.deleteOrganizations(organizationId);
        return JsonVO.success(ErrorCodeConstants.SUCCESS);
    }

    @ApiOperation("更新组织")
    @PutMapping("update-organizations")
    @Override
    public JsonVO<String> updateOrganizations(@RequestBody UmsOrganizationsUpdateDTO updateDTO) {
        iUmsOrganizationsService.updateOrganizations(updateDTO);
        return JsonVO.success(ErrorCodeConstants.SUCCESS);
    }

    @ApiOperation("给员工进行分组")
    @PostMapping("/adduser-in-organizations")
    @Override
    public JsonVO<String> addUserInOrganization(@RequestBody UmsOrganizationUserAddDTO addDTO) {
        iUmsOrganizationsService.addUserInOrganization(addDTO);
        return JsonVO.success(ErrorCodeConstants.SUCCESS);
    }

    @ApiOperation("将员工从组织中删除")
    @PostMapping("/deleteuser-in-organizations")
    @Override
    public JsonVO<String> deleteUserInOrganization(@RequestBody UmsOrganizationUserDeleteDTO deleteDTO) {
        iUmsOrganizationsService.deleteUserInOrganization(deleteDTO);
        return JsonVO.success(ErrorCodeConstants.SUCCESS);
    }

    @ApiOperation("获得组织架构(根据根节点id)")
    @GetMapping("/get-all-organizations")
    @Override
    public JsonVO<UmsOrganizationFindAllDTO> getAllOrganization(@RequestParam String root) {
        UmsOrganizationFindAllDTO allOrganization = iUmsOrganizationsService.getAllOrganization(root);
        return JsonVO.success(allOrganization);
    }
}
